<?php
namespace Home\Model;
use Home\Model\BaseModel;

class B2cMemberAddrsModel extends BaseModel{



    /**
     * @return array
     * 选择收货地址
     */
    public function changeAddress($member_id,$addrId){
        //开启事物


        $this->startTrans();
        $result = $this->where(array('member_id'=>$member_id))->save(array('def_addr'=>0));
        $dt = $this->where(array('addr_id'=>$addrId))->save(array('def_addr'=>1));
        if($result !== false && $dt !== false){
            // 提交事务
            $this->commit();
            return array('msg'=>'更新默认地址成功','status'=>1,'url'=>url('Home/Carts/cart'));
        }else{
            // 事务回滚
            $this->rollback();
            return array('msg'=>'更新默认地址失败','status'=>0);
        }

    }

}